package leetcode.code695.MaxAreaofIsland;

public class Solution69501 extends MaxAreaofIsland {

	@Override
	public int maxAreaOfIsland(int[][] grid) {
		int max = 0;
		for (int i = 0; i < grid.length; i++) {
			for (int j = 0; j < grid[0].length; j++) {
				if (grid[i][j] == 1) {
					max = Math.max(max, this.areaOfIsland(grid, i, j));
				}
			}
		}
		return max;
	}

	public int areaOfIsland(int[][] grid, int x, int y) {
		int size = 0;
		if (x >= 0 && y >= 0 && x < grid.length && y < grid[0].length && grid[x][y] == 1) {
			grid[x][y] = 2;
			size++;
			size += this.areaOfIsland(grid, x - 1, y);
			size += this.areaOfIsland(grid, x + 1, y);
			size += this.areaOfIsland(grid, x, y - 1);
			size += this.areaOfIsland(grid, x, y + 1);
		}
		return size;
	}

	public static void main(String[] args) {
		Solution69501 so = new Solution69501();
//		so.debug1();
		so.debug2();
	}

}
